﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Threading;

namespace S7.Windows.Reservations
{
    /// <summary>
    /// Interaction logic for ShowReservations.xaml
    /// </summary>
    public partial class ShowReservations : Window
    {
        public ShowReservations()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Thread thrSearch = new Thread(new ThreadStart(() =>
                {
                    try
                    {
                        List<Booking> lstBookings = Booking.Search();
                        dgReservations.Dispatcher.Invoke(new ThreadStart(() =>
                            {
                                try
                                {
                                    dgReservations.ItemsSource = lstBookings;
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show(ex.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
                                }
                                
                            }), null);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
                    }
                    
                }));
            thrSearch.IsBackground = true;
            thrSearch.Start();
        }
    }
}
